GBML manual / Drawing

sprite

The sprite this instance is drawn with. Set to nothing-equivalent (leave unset) to draw nothing.

Syntax

sprite: sprite

Description

Which sprite this instance is drawn with by default drawing (see Where the machine shows through). Leave it unset and the instance draws nothing at all - a common, deliberate choice for a purely logical object (a spawner, a trigger zone) that has no visual of its own. Every sprite a project's assets declare becomes one of these values; assigning one is how an object picks its look, and reassigning it later (a hurt frame, a different costume) is how that look changes. A sprite this instance has never shown before claims its own palette bank (and sprite tile set) the moment it's assigned, the same real cost instance_create pays for a whole new instance - see Budgets.

A sprite can be any size, up to 512 x 512 pixels. The Game Boy Advance can only draw a sprite as one of a few shapes (8 x 8 up to 64 x 64, and a few wider or taller ones), so a picture that is not one of them is cut into pieces when your game is built, ahead of time, with nothing for you to do: pieces that would be empty (a ring, a letter L) are left out, and every frame of the sprite is cut the same way. In your game it is still ONE sprite: it has one origin, one collision box, one palette and one set of pictures, you put it on an object like any other, and it moves, turns, scales, mirrors, animates and wears sprite effects (a Flip included) all together, about its origin. draw_self and draw_sprite draw it whole too, and its depth is the object's. sprite_width and sprite_height answer for the whole picture.

What it costs the console, which Paint shows beside the size ("Split: 5 pieces, 72 tiles"): each piece is a sprite of the console's own (it has 128 at once and 1,024 tiles of picture memory for them), and the console draws sprites one screen line at a time with only room for about 1,210 sprite pixels on each line, so a very wide picture, or several big ones side by side, can lose sprites at the end of a line. A turned or scaled sprite costs a little more per line, and where two pieces meet at an odd angle a seam one pixel wide can show. Not yet on a big sprite: the Wobble and Distort sprite effects (they bend one piece only) and a lean (xshear); every other sprite effect plays on the whole. A picture of scenery that never moves is better painted into the room's background, which costs no sprites and no time on a line. A sprite drawn by a Draw event can have up to 12 pieces (more with Sprites in one drawn thing in Project Settings).

Example

sprite = spr_doc_hero;

Sets this instance's look once, in Create - the usual place, since almost every object keeps the same base sprite for its whole life and only frame changes from there.

On the GBA

A project’s sprite names become a generated enum-like set of ids (S2.3.1); the engine resolves whichever one you assign to the real graphics asset.

See also: Budgetsinstance_create